package com.znxs.bs_c.mapper;

import com.znxs.bs_c.entity.Menu;
import com.znxs.bs_c.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 左拿
 * @since 2023-08-21
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    // 根据roleId查询menuid
    @Select("select menu_id from sys_role_menu where role_id = #{roleId}")
    List<Integer> getMenuIdByRoleId(@Param("roleId")Integer roleId);

    // 添加menu_role关系
    @Insert("insert into sys_role_menu values(#{roleId},#{menuId})")
    boolean addMenuIdAndRoleId(@Param("roleId")Integer roleId,@Param("menuId")Integer menuId);
    // 删除对应role 的所有菜单
    @Delete("delete from sys_role_menu where role_id = #{roleId}")
    boolean deleteMenuIdAndRoleId(@Param("roleId")Integer roleId);

    // 根据role唯一标识寻找role id
    @Select("select id from sys_role where flag = #{flag}")
    Integer getRoleIdByFlag(@Param("flag") String flag);


}
